package com.jianyun.jyzs.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.amap.api.services.core.PoiItem;
import com.jianyun.jyzs.R;
import com.jianyun.jyzs.activity.CrmMapLocationActivity;

import java.util.ArrayList;

/**
 * Created by mlli on 2017/8/18.
 */

public class CrmMapLocationAdapter extends RecyclerView.Adapter {

    private CrmMapLocationActivity context;
    private ArrayList<PoiItem> list;

    public CrmMapLocationAdapter(CrmMapLocationActivity context) {
        this.context = context;
    }

    public void setList(ArrayList<PoiItem> list) {
        this.list = list;
        notifyDataSetChanged();
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = View.inflate(context, R.layout.ac_crm_search_item, null);
        return new MyHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        MyHolder myHolder = (MyHolder) holder;
        final PoiItem poiItem = list.get(position);
        myHolder.address.setText(poiItem.getTitle());
        myHolder.addressdetial.setText(poiItem.getProvinceName()+poiItem.getDirection()+poiItem.getAdName()+poiItem.getBusinessArea()+poiItem.getSnippet());
        myHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                context.getLocationResult(poiItem);
            }
        });
    }

    @Override
    public int getItemCount() {
        return list==null?0:list.size();
    }

    class MyHolder extends RecyclerView.ViewHolder {

        private final TextView address;
        private final TextView addressdetial;


        public MyHolder(View itemView) {
            super(itemView);
            address = (TextView) itemView.findViewById(R.id.address);
            addressdetial = (TextView) itemView.findViewById(R.id.addressdetial);
        }
    }
}
